package cn.dxh.stagefinal.controller;

import cn.dxh.stagefinal.bean.Employee;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.websocket.Session;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 2019/12/9 16:55
 *
 * @author Wenhao Lee
 * 心向远方，不负厚望。
 */
@Controller
public class IndexController {
    @RequestMapping("/head")
    public String head() {
        return "head";
    }

    @RequestMapping("/left")
    public String left() {
        return "left";
    }

    @RequestMapping("/right")
    public String right() {
        return "right";
    }

    @RequestMapping("/index")
    public String index() {
        return "index";
    }

    @RequestMapping("/toLogin")
    public String toLogin() {
        return "login";
    }

    @RequestMapping("/")
    public void isLoginHandler(HttpServletRequest requests) {
        HttpSession session = requests.getSession();
        Employee currentUser = (Employee) session.getAttribute("currentUser");
        if (currentUser == null) {
            toLogin();
        } else {
            index();
        }
    }

    @RequestMapping("/error400")
    public String error400() {
        return "error400Page";
    }

    @RequestMapping("/error401")
    public String error401() {
        return "error401Page";
    }

    @RequestMapping("/error404")
    public String error404() {
        return "error404Page";
    }

    @RequestMapping("/error500")
    public String error500() {
        return "error500Page";
    }

}
